/**
 * 系统管理 用户管理
 */
<template>
  <div>
    <!-- 面包屑导航 -->
    <el-breadcrumb separator-class="el-icon-arrow-right">
      <el-breadcrumb-item :to="{ path: '/' }">首页</el-breadcrumb-item>
      <el-breadcrumb-item>用户管理</el-breadcrumb-item>
    </el-breadcrumb>
    <NoPermission
      v-if="!authFilter(permissionObj, 'index')">
    </NoPermission>

    <div v-else>

      <!-- 搜索筛选 -->
      <el-form :inline="true" :model="formInline" class="user-search">
        <el-form-item label="搜索：">
          <el-select size="small" v-model="formInline.status" placeholder="状态（全部）" clearable>
            <el-option label="全部" value=""></el-option>
            <el-option label="启用" value="Y"></el-option>
            <el-option label="禁用" value="N"></el-option>
          </el-select>
        </el-form-item>
        <el-form-item label="">
          <el-input size="small" v-model="formInline.userName" placeholder="输入用户名" clearable></el-input>
        </el-form-item>
  <!--      <el-form-item label="">-->
  <!--        <el-input size="small" v-model="formInline.roleIdName" placeholder="输入角色" clearable></el-input>-->
  <!--      </el-form-item>-->
        <el-form-item>
          <el-button size="small" type="primary" icon="el-icon-search" @click="search">搜索</el-button>
          <el-button size="small" type="primary" icon="el-icon-plus" @click="handleEdit(null, {}, true)"
            v-if="authFilter(permissionObj, 'add')">
          添加
          </el-button>
        </el-form-item>
      </el-form>
      <!--列表-->
      <div class="relative">
        <el-table
          :header-cell-style="{'font-weight': '600', 'color':'#333'}"
          size="small" @selection-change="selectChange" :data="listData" highlight-current-row v-loading="loading" border element-loading-text="拼命加载中" style="width: 100%;">
          <el-table-column align="center" type="selection" width="50">
          </el-table-column>
          <el-table-column align="center" sortable prop="userName" label="用户名" min-width="120">
          </el-table-column>
          <el-table-column align="center" sortable prop="roleName" label="角色名称" min-width="120">
          </el-table-column>
          <el-table-column align="center" sortable prop="email" label="邮箱" min-width="120">
          </el-table-column>
          <el-table-column align="center" sortable prop="phone" label="手机号码" min-width="120">
          </el-table-column>
          <el-table-column align="center" sortable prop="statusName" label="状态" min-width="120">
          </el-table-column>
  <!--        <el-table-column align="center" sortable prop="status" label="禁用状态" min-width="80">-->
  <!--          <template slot-scope="scope">-->
  <!--            <el-switch v-model="scope.row.status=='1'?nshow:fshow" active-color="#13ce66" inactive-color="#ff4949" -->
  <!--                       @change="editType(scope.$index, scope.row)">-->
  <!--            </el-switch>-->
  <!--          </template>-->
  <!--        </el-table-column>-->
          <el-table-column align="center" sortable prop="accountType" label="账户类型" min-width="120">
          </el-table-column>
          <el-table-column align="center" sortable prop="createTime" label="创建时间" min-width="120">
            <template slot-scope="scope">
              <div>{{scope.row.createTime|timestampToDay}}</div>
            </template>
          </el-table-column>
          <el-table-column align="center" sortable prop="creatUser" label="创建用户" min-width="120">
          </el-table-column>
          <el-table-column align="center" label="操作" min-width="430" fixed="right" :min-width="operaWidth">
            <template slot-scope="scope">
              <el-button size="mini" @click="handleEdit(scope.$index, scope.row,false)"
                         v-if="authFilter(permissionObj, 'update')">编辑</el-button>
              <el-button size="mini" type="danger" @click="deleteColumn(scope.$index, scope.row)"
                         v-if="authFilter(permissionObj, 'delete')"
                         :disabled="scope.row.pRid==0">
                         删除
              </el-button>
<!--              <el-button size="mini" type="success" @click="dataAccess(scope.$index, scope.row)"-->
<!--                         v-if="authFilter(permissionObj, 'permissions')">数据权限</el-button>-->
              <el-button size="mini" type="success" @click="resetpwd(scope.$index, scope.row)"
                         v-if="authFilter(permissionObj, 'reset')">重置密码</el-button>
              <el-button size="mini"
                         :type="scope.row.status=='N' ? 'success': 'danger'"
                         @click="editLock(scope.$index, scope.row)"
                         :disabled="scope.row.pRid==0"
                         v-if="authFilter(permissionObj, 'status')">
                {{ scope.row.status=='N' ? "启用" : "禁用" }}
              </el-button>
            </template>
          </el-table-column>
        </el-table>
        <!-- 分页组件 -->
        <Pagination v-bind:child-msg="pageparm" @callFather="callFather"></Pagination>
      </div>

    </div>

    <!-- 编辑界面 -->
    <el-dialog :title="title" :visible.sync="editFormVisible" width="50%" @close='closeDialog("edit", "editForm")'
               style="margin-left: 200px;">
      <el-form label-width="80px" ref="editForm" :model="editForm" :rules="rules"
               label-position="top">
<!--        <el-form-item label="用户名" prop="userName"-->
<!--          v-if="isAdd&&!editForm.userName">-->
<!--          <el-button size="small" type="primary" @click="showChoose">选择用户</el-button>-->
<!--        </el-form-item>-->
<!--        <el-form-item label="用户名" prop="userName"-->
<!--                      v-if="!isAdd || editForm.userName">-->
<!--          <el-input size="small" v-model="editForm.userName" disabled placeholder="请选择用户"></el-input>-->
<!--        </el-form-item>-->
        <el-row>
          <el-col :span="12" class="pdr10">
            <el-form-item label="用户名" prop="userName">
              <el-input size="small" v-model="editForm.userName" auto-complete="off" placeholder="请输入用户名"
                        :maxlength="100" show-word-limit clearable></el-input>
            </el-form-item>
            <el-form-item label="密码" prop="passWord">
              <el-input size="small" v-model="editForm.passWord" auto-complete="off" placeholder="请输入密码"
                        clearable></el-input>
            </el-form-item>
            <el-form-item label="密码有效期" prop="effective">
              <el-select size="small" v-model="editForm.effective" placeholder="请选择" class="userRole"
                         :disabled="editForm.pRid==0"
                         clearable>
                <el-option v-for="type in effectiveList" :label="type.label" :value="type.type" :key="type.type"></el-option>
              </el-select>
            </el-form-item>
            <el-form-item label="角色名称" prop="roleName">
              <el-select
                size="small"
                v-model="editForm.roleName"
                :disabled="editForm.pRid==0"
                placeholder="请选择"
                class="userRole"
                clearable>
                <el-option
                  v-for="type in roleNameList"
                  :label="type.roleName"
                  :value="type.roleName"
                  :key="type.roleName"
                  :disabled="type.pRid==0">

                </el-option>
              </el-select>
            </el-form-item>
            <el-form-item label="账户类型" prop="accountType">
              <el-input size="small" v-model="editForm.accountType" auto-complete="off" placeholder="请输入账户类型"
                        clearable></el-input>
            </el-form-item>
          </el-col>
          <el-col :span="12" class="pdl10">
            <el-form-item label="邮箱" prop="email">
              <el-input size="small" v-model="editForm.email" auto-complete="off" placeholder="请输入邮箱"
                        :maxlength="100" show-word-limit clearable></el-input>
            </el-form-item>
            <el-form-item label="确认密码" prop="passWordComfirm">
              <el-input size="small" v-model="editForm.passWordComfirm" auto-complete="off" placeholder="请输入确认密码"
                        clearable></el-input>
            </el-form-item>
            <el-form-item label="手机号码" prop="phone">
              <el-col :span="10" class="pdr20">
                <el-select size="small" v-model="editForm.code" placeholder="请选择"
                           clearable>
                  <el-option v-for="type in codeList" :label="type.label" :value="type.code" :key="type.code"></el-option>
                </el-select>
              </el-col>
              <el-col :span="14">
                <el-input size="small" v-model="editForm.phone" auto-complete="off" placeholder="请输入手机号码"
                          :maxlength="50" show-word-limit clearable></el-input>
              </el-col>
            </el-form-item>
            <el-form-item label="状态" prop="status">
              <el-radio v-model="editForm.status" label="N"
                        :disabled="editForm.pRid==0">
                禁用
              </el-radio>
              <el-radio v-model="editForm.status" label="Y"
                        :disabled="editForm.pRid==0">
                启用
              </el-radio>
            </el-form-item>
          </el-col>
        </el-row>
      </el-form>
      <div slot="footer" class="dialog-footer">
        <el-button size="small" @click='closeDialog("edit", "editForm")'>取消</el-button>
        <el-button size="small" type="primary" :loading="loading" class="title" @click="submitForm('editForm')">保存</el-button>
      </div>
    </el-dialog>
    <!-- 数据权限 -->
    <el-dialog title="数据权限" :visible.sync="dataAccessshow" width="70%" @close='closeDialog("perm")'
               style="margin-left: 200px;">
      <div
        class="jurisdiction-content">
        <div class="jurisdiction-content-checkbox fs14 color66 scrollBar">
          <el-tree
            ref="selectTree"
            node-key="id"
            :data="userDataList"
            :props="defaultProps"
            show-checkbox
            default-expand-all
            :check-strictly="true"
            :default-checked-keys="[]"
            :check-on-click-node="true"
            :expand-on-click-node="false"
            @check="nodeCheck">
            <span
              slot-scope="{ node }"
              :class="{ 'node-label': node.level == 1}">
                {{ node.label }}
              </span>
          </el-tree>
        </div>
      </div>
      <div slot="footer" class="dialog-footer">
        <el-button size="small" @click='closeDialog("perm")'>取消</el-button>
        <el-button size="small" type="primary" :loading="loading" class="title" @click="menuPermSave">保存</el-button>
      </div>
    </el-dialog>
  </div>
</template>

<script>
// 导入请求方法
import Pagination from '@/components/Pagination'
import {mapGetters} from "vuex";
import config from "@/api/config.js";
import * as dd from 'dingtalk-jsapi' // 此方式为整体加载，也可按需进行加载
export default {
  // 注册组件
  components: {
    Pagination
  },
  data() {
    return {
      // nshow: true, //switch开启
      // fshow: false, //switch关闭
      loading: false, //是显示加载
      title: '添加用户',
      editFormVisible: false, //控制编辑页面显示与隐藏
      dataAccessshow: false, //控制数据权限显示与隐藏
      unitAccessshow: false, //控制所属单位隐藏与显示
      // 编辑与添加
      editForm: {
        userId: '',
        userName: '',
        status: 'Y',
        roleName: '',
        //用户分级：
        rid: '',
        createTime: '',
        creatUser: '',
        code: this.$store.state.codeCurrent,
        phone: '',
        email: '',
        accountType: '',
        passWord: '',
        passWordComfirm: '',
        effective: 0,
      },
      isAdd: false,
      effectiveList: [
        {
          type: 0,
          label: '无限'
        },
        {
          type: 30,
          label: '30天'
        },
        {
          type: 50,
          label: '50天'
        }
      ],
      roleNameList: [],
      // 部门参数
      unitparm: {
        userIds: '',
        deptId: '',
        deptName: ''
      },
      // 选择数据
      selectdata: [],
      codeList: this.$store.state.codeList,
      statusList: [
        {
          value: "N",
          label: "禁用"
        },
        {
          value: "Y",
          label: "启用"
        }
      ],
      // rules表单验证
      rules: {
        userName: [
          { required: true, message: '请输入用户名', trigger: 'blur' }
        ],
        passWord: [{ required: true, message: '请输入密码', trigger: 'blur' }],
        passWordComfirm: [{ required: true, message: '请输入确认密码', trigger: 'blur' }],
        effective: [
          { required: true, message: '请选择密码有效期', trigger: 'change' }
        ],
        roleName: [
          { required: true, message: '请选择角色名称', trigger: 'change' }
        ],
        status: [
          { required: true, message: '请选择禁用状态', trigger: 'change' }
        ],
        // email: [{ required: true, message: '请输入邮箱', trigger: 'blur' }],
        email: [
          { required: true, message: '请输入邮箱', trigger: 'blur' },
          {
            pattern: /^[A-Za-z0-9\u4e00-\u9fa5]+@[a-zA-Z0-9_-]+(\.[a-zA-Z0-9_-]+)+$/,
            required: true,
            message: '请输入正确的邮箱',
            trigger: 'blur'
          }
        ],
        phone: [{ required: true, message: '请输入手机号码', trigger: 'blur' }],
        // phone: [
        //   { required: true, message: '请输入手机号', trigger: 'blur' },
        //   {
        //     pattern: /^1(3\d|47|5((?!4)\d)|7(0|1|[6-8])|8\d)\d{8,8}$/,
        //     required: true,
        //     message: '请输入正确的手机号',
        //     trigger: 'blur'
        //   }
        // ],
      },
      // 删除用户
      seletedata: {
        ids: '',
      },
      // 重置密码
      resetpsd: {
        userId: '',
      },
      // 用户下线
      offline: {

      },
      // 请求数据参数
      formInline: {
        page: 1,
        pagenum: 10,
        userName: '',
        // roleName: '',
        status: ''
      },
      //用户数据
      listData: [],
      roleIdList: [],
      // 数据权限
      userDataList: [],
      filterText: '',
      defaultProps: {
        children: 'children',
        label: 'title',
        disabled (data, node) {//带子级的节点不能选中
          if (data.children && data.children.length > 0) {
            return true
          } else {
            return false
          }
        }
      },
      nodeCheckDataArr: [], // 当前选中的值列表
      // 选中
      checkmenu: [],
      //参数role
      saveroleId: '',
      // 分页参数
      pageparm: {
        currentPage: 1,
        pageSize: 10,
        total: 10
      },
      // 权限管理
      ruleMenuIndex: 'data', // 默认模块 工作台
      pid: '',
      // 字段授权
      setFieldLabel: '',
      setFieldShow: false,
      id: '',
      // 防重复点击
      allowRequest: true,
    }
  },

  /**
   * 数据发生改变
   */
  watch: {

  },
  computed: {
    ...mapGetters(['userInfo', 'userAuthList','roleInfo']),
    permissionObj(){
      if(this.userAuthList&&this.userAuthList.length>0){
        return this.authListFilter(this.userAuthList,'customManagement', 'user')
      }
    },
    // 操作列表宽度
    operaWidth(){
      const vm = this
      const minWidth = 120
      const len = vm.authFilterLen(this.permissionObj, 'update', 'delete', 'permissions', 'reset', 'status').length
      return len > 0 ? vm.multiply(len,90) : minWidth
    }
  },

  /**
   * 创建完毕
   */
  created() {
    //this.roleListGet().then(()=>{
    //  this.getData(this.formInline)
    //})
    this.roleListGet()
    this.getData(this.formInline)
    console.log('userInfo', this.userInfo)
  },

  /**
   * 里面的方法只有被调用才会执行
   */
  methods: {
    // 获取角色列表
    roleListGet() {
      const vm = this;
      /***
       * 调用接口，注释上面模拟数据 取消下面注释
       */
      //用户分级
      let param = {
          rid: vm.roleInfo.rid,
          includingSuper: 0,
      }
      return  this.apiUrl.roleList(param,'POST')
        .then(res => {
          const { data:{list=[]},code, msg } = res
          if (code != 0) {
            // vm.$message({
            //   type: 'error',
            //   message: res.msg
            // })
          } else {
            vm.roleNameList = list;
          }
        })
        .catch(err => {
          if(err&&err.isCancel) return
        })
    },
    // 获取数据方法
    getData(parameter) {
      this.loading = true

      /***
       * 调用接口，注释上面模拟数据 取消下面注释
       */
      // 获取用户列表
      const vm = this
      //用户分级
      parameter = {
        ...parameter,
        rid: vm.roleInfo.rid
      }
      vm.apiUrl.userList(parameter,"POST")
        .then(res => {
        vm.loading = false
        const { data:{list=[],totalnum},code, msg } = res
          if (code != 0) {
          vm.$message({
            type: 'error',
            message: msg
          })
        } else {
          const listNew = list.map((item)=>{
            return {
              ...item,
              statusName: vm.showSelectTxt(vm.statusList,item.status),
              passWord: '',
              passWordComfirm: ''
            }
          })
          vm.listData = listNew
          // 分页赋值
          vm.pageparm.currentPage = vm.formInline.page
          vm.pageparm.pageSize = vm.formInline.pagenum
          vm.pageparm.total = totalnum
        }
      })
    },
    // 分页插件事件
    callFather(parm) {
      const vm = this
      vm.formInline = {
        ...vm.formInline,
        page: parm.currentPage,
        pagenum: parm.pageSize
      }
      vm.getData(vm.formInline)
    },
    //搜索事件
    search() {
      const vm = this
      vm.formInline = {
        ...vm.formInline,
        page: 1
      }
      vm.getData(vm.formInline)
    },
    // 启用禁用
    editLock: function(index, row) {
      const vm = this
      vm.loading = true
      let parm = {
        status: '',
        userId: '',
      }
      parm.userId = row.userId
      parm.status = (row.status == 'N' ? 'Y' : 'N')
      // 修改状态
      vm.apiUrl.userLock(parm,"POST")
      .then(res => {
        vm.loading = false
        const { code,msg } = res;
        if (code != 0) {
          vm.showMessageMin({
            type: 'error',
            message: msg
          })
        } else {
          vm.showMessageMin({
            type: 'success',
            message: (row.status=='N' ? "启用" : "禁用") +'状态修改成功'
          })
          vm.getData(vm.formInline)
        }
      })
    },
    //显示编辑界面
    async handleEdit(index, row, isAdd=false) {
      const vm = this
      vm.isAdd = isAdd
      vm.title =  (vm.isAdd ? '添加用户' : '修改用户')
      if (!vm.isAdd) {
        vm.editForm = {
          ...row
        }
      } else {
        // for(let path in vm.editForm){
        //   vm.editForm[path] = ''
        // }
        vm.editForm = {}
        vm.editForm = {
          ...vm.editForm,
          code: this.$store.state.codeCurrent,
          status: 'Y',
          effective: 0,
        }
        vm.$nextTick(()=>{
          vm.clearValidate('editForm')
        })
      }
      vm.editFormVisible = true
    },
    // 编辑、添加提交方法
    submitForm(editData) {
      const vm = this
      let param = {
        ...vm.editForm,
        passWord: vm.$md5(vm.editForm.passWord),
        passWordComfirm: vm.$md5(vm.editForm.passWordComfirm),
      }
      if(param.passWord!=param.passWordComfirm){
        if(!vm.allowRequest) return
        vm.allowRequest=false
        vm.showMessageMin({
          type: 'error',
          message: '密码与确认密码不一致'
        })
        vm.sleep(1500).then(()=>{
          vm.allowRequest=true
        })
        return
      }
      //用户分级：新增默认传rid+creatUser
      if (vm.isAdd) {
        param.creatUser = vm.userInfo.userName
        if(!vm.editForm.rid){
          const rid = vm.roleNameList.filter(item=>item.roleName == vm.editForm.roleName)[0].rid
          vm.editForm.rid = rid
          param.rid = vm.editForm.rid
        }
      }
      vm.$refs[editData].validate(valid => {
        if (valid) {
          // 请求方法
          vm.openFullScreen();
          let request = null
          if (!vm.isAdd) {
            request = vm.apiUrl.userEdit
          } else {
            request = vm.apiUrl.userAdd
          }
          request(param,"POST")
            .then(res => {
              vm.closeFullScreen(vm.openFullScreen());
              const { code,msg } = res;
              if (code != 0) {
                vm.showMessageMin({
                  type: 'error',
                  message: msg
                })
              } else {
                vm.editFormVisible = false
                vm.showMessageMin({
                  type: 'success',
                  message: '数据保存成功！'
                })
                vm.getData(vm.formInline)
              }
            })
        } else {
          return false
        }
      })
    },
    handleClick(data, checked, node) {
      const vm = this
      if (checked) {
        vm.$refs.tree.setCheckedNodes([])
        vm.$refs.tree.setCheckedNodes([data])
        vm.unitparm.deptId = data.id
        vm.unitparm.deptName = data.name
        //交叉点击节点
      } else {
      }
    },
    // 选择复选框事件
    selectChange(val) {
      this.selectdata = val
    },
    // 关闭编辑、增加弹出框
    clearValidate(formName){
      if(!this.$refs[formName]) return
      this.$refs[formName].clearValidate()
    },
    resetForm(formName) {
      if(!this.$refs[formName]) return
      this.$refs[formName].resetFields();
    },
    closeDialog(dialog, formName) {
      const vm = this
      if (dialog == 'edit') {
        vm.editFormVisible = false
      } else if (dialog == 'perm') {
        vm.dataAccessshow = false
      } else if (dialog == 'unit') {
        vm.unitAccessshow = false
      }
      this.clearValidate(formName);
    },
    // 删除用户
    deleteColumn(index, row) {
      const vm = this
      vm.$confirm('确定要删除吗?', '信息', {
        confirmButtonText: '确定',
        cancelButtonText: '取消',
        type: 'warning'
      })
        .then(() => {
          // 删除
          vm.openFullScreen();
          vm.apiUrl.userDelete({
            userId:row.userId
          },"POST")
            .then(res => {
              vm.closeFullScreen(vm.openFullScreen());
              const { code,msg } = res;
              if (code != 0) {
                vm.showMessageMin({
                  type: 'error',
                  message: msg
                })
              } else {
                vm.showMessageMin({
                  type: 'success',
                  message: '数据已删除!'
                })
                vm.getData(vm.formInline)
              }
            })
        })
        .catch(() => {
          vm.showMessageMin({
            type: 'info',
            message: '已取消删除!'
          })
        })
    },
    // 重置密码
    resetpwd(index, row) {
      const vm = this
      vm.resetpsd.userId = row.userId
      vm.$confirm('确定要重置密码吗?', '信息', {
        confirmButtonText: '确定',
        cancelButtonText: '取消',
        type: 'warning'
      })
        .then(() => {
        vm.openFullScreen();
          vm.apiUrl.userResetPsw(vm.resetpsd,"POST")
            .then(res => {
            vm.closeFullScreen(vm.openFullScreen());
            const { code,msg } = res;
              if (code != 0) {
                vm.showMessageMin({
                  type: 'error',
                  message: msg
                })
              } else {
                vm.showMessageMin({
                  type: 'success',
                  message: '重置密码成功!'
                })
                vm.sleep(2000).then(()=>{
                  vm.$store.commit('clearMember')
                  vm.$router.push({ path: '/login' })
                })
                //vm.getData(vm.formInline)
              }
            })
        })
        .catch(() => {
          vm.showMessageMin({
            type: 'info',
            message: '取消重置密码!'
          })
        })
    },
    // 数据权限
    dataAccess: function(index, row) {
      const vm = this
      vm.openFullScreen();
      vm.apiUrl.userDataList()
        .then(res => {
          vm.closeFullScreen(vm.openFullScreen());
          const { code,msg,data:{
            list:[]
          } } = res;
          if (code != 0) {
            vm.showMessageMin({
              type: 'error',
              message: msg
            })
          } else {
            vm.userDataList = list
            vm.saveroleId = row.userId
            vm.dataAccessshow = true

            // vm.checkmenu = vm.changemenu(data)
            // vm.userDataList = vm.changeArr(data)
          }
        })
        .finally(()=>{
          vm.closeFullScreen(vm.openFullScreen());
        })
    },
    //数据格式化
    changeArr(data) {
      var pos = {}
      var tree = []
      var i = 0
      while (data.length != 0) {
        if (data[i].pId == 0) {
          tree.push({
            id: data[i].id,
            name: data[i].name,
            pId: data[i].pId,
            open: data[i].open,
            checked: data[i].checked,
            children: []
          })
          pos[data[i].id] = [tree.length - 1]
          data.splice(i, 1)
          i--
        } else {
          var posArr = pos[data[i].pId]
          if (posArr != undefined) {
            var obj = tree[posArr[0]]
            for (var j = 1; j < posArr.length; j++) {
              obj = obj.children[posArr[j]]
            }

            obj.children.push({
              id: data[i].id,
              name: data[i].name,
              pId: data[i].pId,
              open: data[i].open,
              checked: data[i].checked,
              children: []
            })
            pos[data[i].id] = posArr.concat([obj.children.length - 1])
            data.splice(i, 1)
            i--
          }
        }
        i++
        if (i > data.length - 1) {
          i = 0
        }
      }
      return tree
    },
    // 选中菜单
    changemenu(arr) {
      let change = []
      for (let i = 0; i < arr.length; i++) {
        if (arr[i].checked) {
          change.push(arr[i].id)
        }
      }
      return change
    },
    // 数据权限-保存
    menuPermSave() {
      const vm = this
      let parm = {
        userId: vm.saveroleId,
        userIds: ''
      }
      let node = vm.$refs.selectTree.getCheckedNodes()
      let moduleIds = []
      if (node.length != 0) {
        for (let i = 0; i < node.length; i++) {
          moduleIds.push(node[i].id)
        }
        // parm.userIds = JSON.stringify(moduleIds)
        parm.userIds = moduleIds.join(',')
      }
      console.log('parm', parm)
      vm.openFullScreen();
      vm.apiUrl.dataListEdit(parm,"POST")
        .then(res => {
            vm.closeFullScreen(vm.openFullScreen());
            const { code,msg } = res;
            if (code != 0) {
              vm.showMessageMin({
                type: 'error',
                message: msg
              })
            } else {
              vm.showMessageMin({
                type: 'success',
                message: '权限保存成功'
              })
              vm.dataAccessshow = false
              vm.getData(vm.formInline)
            }
        })
    },
    // 下线用户
    offlineUser(index, row) {
      const vm = this
      vm.$confirm('确定要禁用' + row.userName + '用户吗?', '禁用确认', {
        confirmButtonText: '确定',
        cancelButtonText: '取消',
        type: 'warning'
      })
        .then(() => {
          vm.openFullScreen();
          vm.apiUrl.usereExpireToken({
            userId:row.userId
          },"POST")
            .then(res => {
              vm.closeFullScreen(vm.openFullScreen());
              const { code,msg } = res;
              if (code != 0) {
                vm.showMessageMin({
                  type: 'error',
                  message: msg
                })
              } else {
                vm.showMessageMin({
                  type: 'success',
                  message: '用户' + row.userName + '强制禁用成功！'
                })
                vm.getData(vm.formInline)
              }
            })
        })
    },
    // 选择当前节点
    nodeCheck(node) {
      // console.log('node', node)
      const vm = this
      if(!vm.nodeCheckDataArr.length || vm.nodeCheckDataArr.length === 1) {
        vm.nodeCheckDataArr.push(node);
      }
      if(vm.nodeCheckDataArr.length > 1) {
        const oldItemIndex = vm.nodeCheckDataArr.findIndex(item => item.parent_id === node.parent_id)
        vm.nodeCheckDataArr.forEach(item => {
          if(item.parent_id === node.parent_id && oldItemIndex !== -1) {
            vm.nodeCheckDataArr.splice(oldItemIndex,1)
          }else {
            vm.nodeCheckDataArr.push(node)
          }
        })
      }
      let ids = vm.nodeCheckDataArr.map(item => item.id) //[6, 14, 18, 20, 24]
      function unique(arr) {
        return Array.from(new Set(arr))
      }
      vm.$refs.selectTree.setCheckedKeys(unique(ids))
    },
    //  部门选择
    showChoose(){
      console.log('showChoose')
      const vm = this
      // this.dd.ready(function() {
      //   this.dd.complexChoose({
      // dd.ready(async function() {
      //   const url = window.location.href.split('#')[0]
      //   await vm.$store.dispatch('nailConfiguration', {
      //     url: url
      //   })
      dd.ready(function() {
        dd.complexChoose({
          responseUserOnly: true,
          corpId: config.corpId,
          // disabledDepartments: ['deptId0', 'deptId1'],
          // disabledUsers: ['userId0', 'userId2'],
          deptId: '0',
          multiple: false,
          title: '选择员工',
          // pickedDepartments: ['deptId0', 'deptId1'],
          // requiredDepartments: ['deptId0', 'deptId1'],
          filterOrgEcological: false,
          // requiredUsers: ['userId0', 'userId2'],
          showLabelPick: true,
          // pickedUsers: ['userId0', 'userId2'],
          showOrgEcological: false,
          rootPage: `CommonOrgContact`,
          // startWithDepartmentId: '0332',
          success: (res) => {
            console.log("complexChoose res", res)
            // const { selectedCount, departments, users } = res;
            const { users } = res;
            if(users&&users.length > 0){
              vm.editForm = {
                ...vm.editForm,
                userName: users[0].name,
                // userRealName: users[0].name,
                userId: users[0].emplId
              }
            }
          },
          fail: () => {},
          complete: () => {},
        })
      })
    }

  }
}
</script>

<style lang="less" scoped>
//.role-authorization /deep/ .el-tree-node__expand-icon {
//  display: none;
//}

.user-search {
  margin-top: 20px;
}
.userRole {
  width: 100%;
}

/* 功能权限管理 */
// 隐藏收起展开按钮
/deep/ .el-tree-node__content>.el-tree-node__expand-icon{
  display: none;
}
/deep/ .jurisdiction-content .jurisdiction-content-checkbox .el-tree .el-tree-node{
  display: inline-block;
}

/deep/ .el-tree-node__expand-icon.expanded{
  display: none;
}
///deep/ .el-tree-node__expand-icon.is-leaf{
//  display: none;
//}
.jurisdiction-content {
  height: calc(100% - 61px);
  position: relative;
  overflow: hidden;

  .node-label {
    font-weight: bold;
    font-size: 15px;
    position: relative;
    .el-button {
      position: absolute;
      top: -8px;
      right: -80px;
      /deep/ span {
        margin-left: 3px;
      }
    }
  }

  .content-left {
    height: 100%;
    margin-right: 250px;
    overflow: hidden;
  }
  .content-right {
    width: 250px;
    position: absolute;
    top: 0;
    right: 0;
    height: 100%;
  }
  .jurisdiction-box {
    padding-bottom: 15px;
    height: calc(100% - 61px);
    overflow: hidden;
    position: relative;
  }
  .jurisdiction-content-checkbox {
    height: calc(75vh - 368px);
    overflow-y: scroll;
    padding: 0 20px;

    /deep/ .el-tree-node__content:hover {
      background-color: white;
      color: #2362FB;
    }
  }
  .jurisdiction-content-checkbox
  .el-tree
  /deep/
  .el-tree-node
  > .el-tree-node__content {
    margin-bottom: 20px;
    width: 180px;
  }
  .jurisdiction-content-checkbox /deep/ .el-tree .el-tree-node {
    white-space: inherit;
    margin-bottom: 5px;
  }
  .jurisdiction-content-checkbox
  /deep/
  .el-tree
  > .el-tree-node
  > .el-tree-node__children
  > .is-expanded
  > .el-tree-node__children
  > .is-expanded {
    display: inline-block;
  }
  .role-authorization /deep/ .el-tree-node__expand-icon {
    display: none;
  }
  .data-radio {
    padding: 5px 30px;
  }
  .data-radio .el-radio {
    display: block;
    margin: 20px 0;
  }
  .el-tree-node.is-expanded>.el-tree-node__children{
    display: flex;
  }

}
// 功能权限管理end
</style>
